﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<AddressBook.Mvc.Controllers.HomeController.ContactModel>" %>
<%@ Import Namespace="MvcContrib.UI.Pager" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	AddressBook - Contact List
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>  
  <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

	<script type="text/javascript">  
   
		function deleteRecord(recordId)  
		{  
			// Perform delete  
			var action = "/Home/Delete/" + recordId;  
               
			var request = new Sys.Net.WebRequest();  
			request.set_httpVerb("DELETE");  
			request.set_url(action);  
			request.add_completed(deleteCompleted);  
			request.invoke();  
		}
   
		function deleteCompleted()  
		{  
			// Reload page  
			window.location.reload();
		}  
   
	</script> 


		<div id="contact_toolbar">
			<div style="float: left;">
				<% using (Html.BeginForm("Index", "Home", FormMethod.Get))
						{ %>
						<div style="float: left;">
							<%= Html.TextBox("SearchCriteria", ViewData["SearchCriteria"])%>
						</div>

						<input type="image" src='<%: Url.Content("~/Content/Images/search_16.png") %>' value="submit" alt="search" style="margin-left: 5px;" />
				<% } %>
			</div>

			<a href='<%: Url.Action("Index", "Home") %>'>
					<img src='<%: Url.Content("~/Content/Images/clear_search_16.png") %>' alt="Clear Search" style="margin-left: 5px;" />
			</a>

			<div style="float: right">
				<%: Html.ActionLink("Add Contact", "Create") %>
			</div>
    </div>

    <table id="ContactTable">
        <tr>
            <th></th>
						<th></th>
            <th>
                First Name
            </th>
            <th>
                Last Name
            </th>
            <th>
                Home Address
            </th>
            <th>
                Home Phone
            </th>
            <th>
                Cell Phone
            </th>
        </tr>

    <% int i = 1; foreach (var item in Model.Contacts)
			 { %>
    
        <tr class='<%= i++ % 2 == 0 ? "alternate" : ""  %>'>
            <td>
								<a href='<%: Url.Action("Edit", "Home", new { id=item.Id }) %>'>
										<img src='<%: Url.Content("~/Content/Images/open_contact_16.png") %>' alt="Edit Contact" />
								</a>
            </td>
						<td>
							<a onclick="deleteRecord(<%= item.Id %>)" href="JavaScript:void(0)">
								<img src='<%: Url.Content("~/Content/Images/delete_16.png") %>' alt="Edit Contact" />
							</a>
						</td>
            <td>
                <%: item.FirstName %>
            </td>
            <td>
                <%: item.LastName %>
            </td>
            <td>
                <%: item.HomeAddress %>
            </td>
            <td>
                <%: item.HomePhone %>
            </td>
            <td>
                <%: item.CellPhone %>
            </td>
        </tr>
    
    <% } %>

    </table>

		<div id="contact_pager">
			<%= Html.Pager(Model.Pagination) %>
		</div>
</asp:Content>

